<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */

 /**
  * Component Name: Contact us
  * Auther: Reazaul Karim
  * Email: info@apprain.com
  */
class Component_Contactus_Register extends appRain_Base_Component
{
	/* Default Menu text */
	const DEFAULT_MENU_TITLE = 'Contact Us';
	const CREATE_SITE_MENU = 'Yes';

	/**
	 * Initialize all resource
	 * in side apprain environment.
	 */
    public function init()
    {
		$Config = App::Helper('Config')->siteInfo();

		// Register CSS
		App::Module('Hook')->setHookName('CSS')
                           ->setAction("register_css_code")
                           ->Register(get_class($this),"register_css_code");

		// Register a Controller to render page
		// and execute ajax request
		App::Module('Hook')->setHookName('Controller')
                           ->setAction("register_controller")
                           ->Register(get_class($this),"register_controller");

		$Config['contactussettings_create_sitemenu'] = isset($Config['contactussettings_create_sitemenu']) ? $Config['contactussettings_create_sitemenu'] : self::CREATE_SITE_MENU;

		// Create a site menu
		if($Config['contactussettings_create_sitemenu'] == 'Yes')
		{
			App::Module('Hook')->setHookName('Sitemenu')
                           ->setAction("register_sitemenu")
                           ->Register(get_class($this),"register_sitemenu");
		}


		App::Module('Hook')->setHookName('Sitesettings')
                           ->setAction("register_definition")
                           ->Register(get_class($this),"register_sitesettings_defination");

		App::Module('Hook')->setHookName('UI')
                           ->setAction("quick_contract_request")
                           ->Register(get_class($this),"add_quick_contract_request_html");
    }

    public function init_on_install(){}

    public function init_on_uninstall(){}

	public function register_css_code()
    {
        return App::Helper('Utility')->fetchFile($this->attachMyPath('css/styles.css'));
    }

	public function register_controller()
    {
        $srcpaths = Array();
        $srcpaths[] =   array('name'=>'Contactus',
                              'controller_path'=>$this->attachMyPath('controllers'));
        return $srcpaths;
    }

	public function register_sitemenu($send)
	{
		$settings = App::Helper('Config')->siteInfo('contactussettings');

		$menu = Array();
		$menu[] = Array(App::Helper('Config')->baseurl("/contactus"),(isset($settings['contactussettings_title']) ? $settings['contactussettings_title'] : self::DEFAULT_MENU_TITLE),'contactus');
		return $menu;
	}

	public function register_sitesettings_defination()
    {
        $srcpaths = Array();
        $srcpaths[] = $this->attachMyPath('sitesettings/settings.xml');
        return array('filepaths'=>$srcpaths);
    }

	 public function add_quick_contract_request_html($send)
    {
		return App::Helper('Utility')->callElementByPath($this->attachMyPath('elements/quickcontact.phtml'));
    }
}